//
//  HMComposeToolbar.m
//  Gegeda_music_MY
//
//  Created by lanou3g on 15/11/4.
//  Copyright © 2015年 周莹. All rights reserved.
//
#import "UIView+Extension.h"
#import "HMComposeToolbar.h"

@implementation HMComposeToolbar

-(id)initWithFrame:(CGRect)frame{
    self = [super  initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor  colorWithPatternImage:[UIImage  imageNamed:@"compose_toolbar_background"]];
        
        //添加所有的子控件
        
        [self  addButtonWithIcon:@"compose_camerabutton_background"  hightIcon:@"compose_camerabutton_background_highlighted" tag:ComposeToolbarButtonTypeCamera];
        
        [self addButtonWithIcon:@"compose_toolbar_picture"  hightIcon:@"compose_toolbar_picture_highlighted" tag:ComposeToolbarButtonTypePicture];
        
      
        [self  addButtonWithIcon:  @"compose_mentionbutton_background" hightIcon:@"compose_mentionbutton_background_highlighted" tag:ComposeToolbarButtonTypeMention];
        
        [self  addButtonWithIcon:@"compose_trendbutton_background"  hightIcon:@"compose_trendbutton_background_highlighted" tag:ComposeToolbarButtonTypeTrend];
        
        [self  addButtonWithIcon:@"compose_emoticonbutton_background"  hightIcon:@"compose_emoticonbutton_background_highlighted"  tag:ComposeToolbarButtonTypeEmotion];
        
        
    }


    return self;


}

/**
 *  添加一个按钮
 *
 *  @param icon     默认图标
 *  @param highIcon 高亮图标
 */

-(void)addButtonWithIcon:(NSString *)icon hightIcon:(NSString *)heightIcon tag:(ComposeToolbarButtonType)tag{
    UIButton *button = [[UIButton  alloc] init];
    button.tag = tag;
    [button  addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [button setImage:[UIImage  imageNamed:icon] forState:UIControlStateNormal];
    [button  setImage:[UIImage  imageNamed:heightIcon] forState:UIControlStateHighlighted];
    [self  addSubview:button];
    
    
    

}

//按钮监听点击
-(void)buttonClick:(UIButton  *)button{

    if ([self.delegate  respondsToSelector:@selector(composeTool:didClickedButton:)]) {
        [self.delegate  composeTool:self didClickedButton:button.tag];
    }



}


-(void)layoutSubviews{

    [super  layoutSubviews];
    int count = self.subviews.count;
    CGFloat buttonW  = self.width/count;
    
    CGFloat buttonH = self.height;
    
    for (int i = 0; i < count; i ++) {
        UIButton  * button = self.subviews[i];
        button.y = 0;
        button.width = buttonW;
        button.height = buttonH;
        button.x = i *buttonW;

    }





}






@end
